<%@tag description="pagination" pageEncoding="UTF-8"%>
<%@ attribute name="recordCount" type="java.lang.Integer" required="true"%>
<%@ attribute name="pageSize" type="java.lang.Integer" required="true"%>
<%
Integer o = (Integer)jspContext.getAttribute("recordCount");
int recordCount = o.intValue();

int pageSize = 2;


int pageCount = recordCount / pageSize;
if (pageCount * pageSize < recordCount) ++pageCount;
%>

<%
String uri = request.getRequestURI();
String query = request.getQueryString();
String url = "";
String pt = "pg=[0-9]+";
String remove = "&cmd=.*";


int currentPage = 1;
String search=request.getParameter("search");
String subje = request.getParameter("subje");
String title=request.getParameter("title");


	if (request.getParameter("pg") != null) {
	   	 currentPage = Integer.parseInt(request.getParameter("pg"));
	   	 url = uri + "?" + query;
		} else {
	   	 if (query == null) url = uri + "?pg=1";
	    	else url = uri + "?" + query + "&pg=1";
		}


url=url.replaceAll(remove, "");
if (currentPage > pageCount) currentPage = pageCount;
int base = ((currentPage - 1) / 10) * 10;

StringBuilder sb=new StringBuilder();
if(request.getParameter("skill")!=null){
for(String s:request.getParameterValues("skill")){
	 sb.append("&skill="+s);
}
}
%>


<div class="pagination pagination-small pagination-centered">
  <ul>
    <% if (base > 0) { %>
      <li><a href='<%= url.replaceAll(pt, "pg=" + base) %>&cmd=<%=request.getParameter("cmd")%><%=sb%>'>&lt;</a></li>
  
    <% } %>

    <% for (int i=1; i<=10; ++i) { %>
      <% int n = base + i; 
         String s = (n == currentPage) ? "active" : ""; 
         if (n > pageCount) break; 
      %>
      <li class='<%= s %>'>
        <a href='<%= url.replaceAll(pt, "pg=" + n) %>&cmd=<%=request.getParameter("cmd")%><%=sb%>' ><%=n%></a>
      </li>
    <% } %>
      
    <% if (base+11 <= pageCount) { %>
       <li><a href='<%= url.replaceAll(pt, "pg=" + (base+11)) %>&cmd=<%=request.getParameter("cmd")%><%=sb%>'>&gt;</a></li>
    <% } %>
  </ul>
</div>
